#ifndef TEXTEDITOR_H
#define TEXTEDITOR_H

#include "resizableimagetextedit.h"
#include <QWidget>
#include <QToolBar>
#include <QAction>
#include <QTextTable>
#include <QSpinBox>
#include <QLabel>
#include <QVBoxLayout>
#include <QPushButton>

class TextEditor : public QWidget
{
    Q_OBJECT

public:
    TextEditor(QWidget *parent = nullptr);
    ~TextEditor();

private slots:
    void alignLeft();
    void alignCenter();
    void alignRight();
    void insertImage();
    void insertTable();
    void applyTableResize();
    void updateTableResizeControls();

private:
    ResizableImageTextEdit *textEdit;
    QToolBar *toolBar;
    QAction *leftAlignAction;
    QAction *centerAlignAction;
    QAction *rightAlignAction;
    QAction *insertImageAction;
    QAction *insertTableAction;

    // 表格调整控件
    QLabel *columnWidthLabel;
    QSpinBox *columnWidthSpinBox;
    QLabel *rowHeightLabel;
    QSpinBox *rowHeightSpinBox;
    QPushButton *applyResizeButton;
    QWidget *tableResizeWidget;

    QTextTable *getSelectedTable();
    void setupTableResizeControls();
    int getCurrentTableRow();
    int getCurrentTableColumn();
    int calculateCellContentHeight(const QTextTableCell &cell);
};

#endif // TEXTEDITOR_H
